﻿<UserControl x:Class="MsbuildLauncher.PropertiesControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:MsbuildLauncher"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <UserControl.Resources>
        <local:IsNullToVisibilityConverter x:Key="IsNullToVisibilityConverter" />
        <local:MultiplyConverter x:Key="MultiplyConverter" />
    </UserControl.Resources>
    
    <ItemsControl ItemsSource="{Binding}" >
        <ItemsControl.Resources>
            <Style TargetType="Label">
                <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:PropertiesControl}}, Path=NameWidth}" />
                <Setter Property="HorizontalContentAlignment" Value="Right" />
                <Setter Property="Foreground" Value="{StaticResource TextBrush}" />
            </Style>

            <Style TargetType="DockPanel">
                <Setter Property="Margin" Value="2" />
            </Style>
        </ItemsControl.Resources>
        
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <DockPanel IsEnabled="{Binding IsEnabled}">
                    <Label DockPanel.Dock="Left" ToolTip="{Binding Name}">
                        <Label.FontSize>
                            <Binding
                                RelativeSource="{RelativeSource AncestorType={x:Type Window}}"
                                Path="FontSize"
                                Converter="{StaticResource MultiplyConverter}"
                                ConverterParameter="0.95" />
                        </Label.FontSize>
                        
                        <TextBlock TextTrimming="CharacterEllipsis" Text="{Binding Name}" />
                    </Label>
                    <ToggleButton 
                        ToolTip="Is the value changed: only changed values used for building"
                        DockPanel.Dock="Right" Width="12" Height="12" 
                        HorizontalAlignment="Center" VerticalAlignment="Center"
                        IsChecked="{Binding IsChanged}" />
                    <StackPanel>
                        <TextBox 
                            Name="textBoxValue"
                            Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}"
                            Visibility="{Binding Items, Converter={StaticResource IsNullToVisibilityConverter}, ConverterParameter=VisibleIfNull}">
                            <TextBox.FontSize>
                                <Binding
                                   RelativeSource="{RelativeSource AncestorType={x:Type Window}}"
                                   Path="FontSize"
                                   Converter="{StaticResource MultiplyConverter}"
                                   ConverterParameter="0.95" />
                            </TextBox.FontSize>
                        </TextBox>
                        <ComboBox SelectedValue="{Binding Value}" ItemsSource="{Binding Items}" IsEditable="True"
                                 Visibility="{Binding Items, Converter={StaticResource IsNullToVisibilityConverter}, ConverterParameter=CollapsedIfNull}">
                            <ComboBox.FontSize>
                                <Binding
                                   RelativeSource="{RelativeSource AncestorType={x:Type Window}}"
                                   Path="FontSize"
                                   Converter="{StaticResource MultiplyConverter}"
                                   ConverterParameter="0.95" />
                            </ComboBox.FontSize>
                        </ComboBox>
                    </StackPanel>
                </DockPanel>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</UserControl>
